home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Diskmonitors / SCSILister / SCSI_lister.c < prev    next >
C/C++ Source or Header  |  1996-09-26  |  5KB  |  182 lines

  1. #include <exec/types.h>
  2. #include <exec/io.h>
  3. #include <exec/execbase.h>
  4. #include <libraries/dos.h>
  5. #include <devices/scsidisk.h>
  6.  
  7. struct   MsgPort        *MyPort;
  8. struct   IOStdReq       *Req;
  9. struct   SCSICmd        SCSIinfo;
  10. UBYTE    CDB[10];
  11. UBYTE    stuff[80];
  12. BPTR     wdw;
  13. int      WB;
  14.  
  15. extern   struct ExecBase *AbsExecBase;
  16.  
  17. char  *AvoidNames[] = {
  18.    "audio.device",         /* System devices we want to skip */
  19.    "clipboard.device",
  20.    "console.device",
  21.    "gameport.device",
  22.    "input.device",
  23.    "keyboard.device",
  24.    "parallel.device",
  25.    "printer.device",
  26.    "ramdrive.device",
  27.    "serial.device",
  28.    "timer.device",
  29.    "trackdisk.device",
  30.  
  31.    "bootdisk.device",      /* Other devices that we don't want */
  32.    "modem0.device",
  33.    "modem1.device",
  34.    "modem2.device",
  35.    "modem3.device",
  36.  
  37.    "!"                     /* End of list */
  38. };
  39.  
  40. void main(argc,argv)
  41. int   argc;
  42. char  **argv;
  43. {
  44.    struct   Node *DevNode;
  45.    char     DevName[80];
  46.    int      i,count=0;
  47.  
  48.    if (argc==0) {       /* Workbench support -- only works w/Lattice 3.03 */
  49.       wdw = Open("CON:0/0/640/200/SCSI test",MODE_NEWFILE);
  50.       if (wdw == NULL) Cleanup(0);
  51.       WB = 1;
  52.    }
  53.    else {
  54.       wdw = Output();
  55.    }
  56.  
  57.    fprintf(wdw,"\nSCSI-direct test application: SCSI device lister\n");
  58.    fprintf(wdw,"Written by Marty Flickinger\n");
  59.    fprintf(wdw,"Copyright © 1990 Xetec, Inc.\n");
  60.  
  61.    MyPort = (struct MsgPort *)CreatePort("CDROM_test",0);
  62.    if (!MyPort) Cleanup("Couldn't make port");
  63.    Req = (struct IOStdReq *)CreateStdIO(MyPort);
  64.    if (!Req) Cleanup("Couldn't make IO");
  65.  
  66. /*   Forbid(); */
  67.    DevNode = AbsExecBase->DeviceList.lh_Head;
  68.    while (DevNode->ln_Succ) {
  69.       strcpy(DevName,DevNode->ln_Name);
  70.  
  71.       for (i=0;;i++) {
  72.          if (AvoidNames[i][0] == '!') {
  73.             ListDevice(DevName);
  74.             count++;
  75.             break;
  76.          }
  77.          if (!strcmp(AvoidNames[i],DevName))
  78.             break;
  79.       }
  80.       DevNode = DevNode->ln_Succ;
  81.    }
  82. /*   Permit(); */
  83.  
  84.    if (count==0)
  85.       fprintf(wdw,"\nDidn't find a SCSI hard disk driver\n");
  86.  
  87.    Cleanup("Done");
  88. }
  89.  
  90.  
  91. Cleanup(msg)
  92. char  *msg;
  93. {
  94.    if (wdw)
  95.       fprintf(wdw,"%ls\n",msg);
  96.  
  97.    if (Req)       DeleteStdIO(Req);
  98.    if (MyPort)    DeletePort(MyPort);
  99.    if ((WB)&&(wdw)) {
  100.       Delay(300);
  101.       Close(wdw);
  102.    }
  103. }
  104.  
  105.  
  106. int ListDevice(devname)
  107. char  *devname;
  108. {
  109.    int   stat,unit,act,ver,rev,known=0;
  110.    int   OpenFlag = 1;
  111.    char  *id;
  112.  
  113.    fprintf(wdw,"\n--- Using \"%ls\" ---\n",devname);
  114.  
  115.    for (unit=0;unit<7;unit++) {
  116.       fprintf(wdw,"Unit #%ld: ",unit);
  117.       OpenFlag = OpenDevice(devname,unit,Req,0);
  118.       if (!OpenFlag) {
  119.          if (!known) {
  120.             ver = ((struct Library *)Req->io_Device)->lib_Version;
  121.             rev = ((struct Library *)Req->io_Device)->lib_Revision;
  122.             id =  (char *)((struct Library *)Req->io_Device)->lib_IdString;
  123.             known++;
  124.          }
  125.          CDB[0] = 18;      /* Construct an "inquiry" command desc. block */
  126.          CDB[4] = 40;
  127.          CDB[1] = CDB[2] = CDB[3] = CDB[5] = 0;
  128.  
  129.          SCSIinfo.scsi_Data = (UWORD *)stuff;   /* Where I want the results */
  130.          SCSIinfo.scsi_Length = 40;             /* Max data to return */
  131.          SCSIinfo.scsi_Command = (UBYTE *)&CDB; /* Pointer to my command */
  132.          SCSIinfo.scsi_CmdLength = 6;           /* It's 6 long */
  133.          SCSIinfo.scsi_Flags = SCSIF_READ;      /* Direction = read */
  134.  
  135.          Req->io_Command = 28;                  /* SCSI direct command */
  136.          Req->io_Data = (APTR)&SCSIinfo;        /* Give custom info */
  137.          Req->io_Length = sizeof(struct SCSICmd);
  138.          DoIO(Req);                             /* Do it! */
  139.          stat = Req->io_Error;
  140.          CloseDevice(Req);
  141.  
  142.          if (stat==HFERR_SelTimeout)
  143.             fprintf(wdw,"No device\n");
  144.          else if (stat==HFERR_BadStatus)
  145.             fprintf(wdw,"Doesn't support SCSI direct command (28)\n");
  146.          else if (stat)
  147.             fprintf(wdw,"Unknown error\n");
  148.          else {
  149.             act = Req->io_Actual;
  150.             if (act<16)
  151.                act = SCSIinfo.scsi_Actual;
  152.  
  153.             if (act>15)
  154.                DoString("",&stuff[8],8);
  155.             if (act>31)
  156.                DoString("  ",&stuff[16],16);
  157.             if (act>35)
  158.                DoString("   Rev:",&stuff[32],4);
  159.             fprintf(wdw,"\n");
  160.          }
  161.       }
  162.       else {
  163.          fprintf(wdw,"No unit\n");
  164.       }
  165.    }
  166.    if (known)
  167.       fprintf(wdw,"Device version %ld.%ld --- %ls\n",ver,rev,id);
  168. }
  169.  
  170.  
  171. DoString(pre,msg,len)
  172. char  *pre,*msg;
  173. int   len;
  174. {
  175.    char  scratch[80];
  176.  
  177.    fprintf(wdw,pre);
  178.    strncpy(scratch,msg,len);
  179.    scratch[len] = 0;
  180.    fprintf(wdw,scratch);
  181. }
  182.